package com.dayuanit.dy14.alipay.alipayspringbootstarter.auto.config;

import com.dayuanit.dy14.alipay.alipayspringbootstarter.auto.handler.AlipayHandler;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties({AlipayProperties.class})
public class AlipayAutoConfig {

    private AlipayProperties alipayProperties;

    public AlipayAutoConfig(AlipayProperties alipayProperties) {
        this.alipayProperties = alipayProperties;
    }

    @Bean
    public AlipayHandler alipayHandler() {
        AlipayHandler alipayHandler = new AlipayHandler();
        alipayHandler.setAliPublicKey(alipayProperties.getAliPublicKey());
        alipayHandler.setAppId(alipayProperties.getAppId());
        alipayHandler.setCharset(alipayProperties.getCharset());
        alipayHandler.setFormat(alipayProperties.getFormat());
        alipayHandler.setMerchantPrivateKey(alipayProperties.getMerchantPrivateKey());
        alipayHandler.setNotfiyUrl(alipayProperties.getNotfiyUrl());
        alipayHandler.setPayGateWay(alipayProperties.getPayGateWay());
        alipayHandler.setProducCode(alipayProperties.getProducCode());
        alipayHandler.setReturnUrl(alipayProperties.getReturnUrl());
        alipayHandler.setSignType(alipayProperties.getSignType());
        alipayHandler.setSubject(alipayProperties.getSubject());
        return alipayHandler;
    }
}
